package com.healthyeating.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.healthyeating.manage.domain.dto.ShopListProductDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthyeating.common.annotation.Log;
import com.healthyeating.common.core.controller.BaseController;
import com.healthyeating.common.core.domain.AjaxResult;
import com.healthyeating.common.enums.BusinessType;
import com.healthyeating.manage.domain.ShopList;
import com.healthyeating.manage.service.IShopListService;
import com.healthyeating.common.utils.poi.ExcelUtil;
import com.healthyeating.common.core.page.TableDataInfo;

/**
 * 清单管理Controller
 *
 * @author 段奇乐
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/manage/buylist")
public class ShopListController extends BaseController {
    @Autowired
    private IShopListService shopListService;

    /**
     * 查询清单管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:buylist:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopList shopList) {
        startPage();
        List<ShopList> list = shopListService.selectShopListList(shopList);
        return getDataTable(list);
    }

    /**
     * 导出清单管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:buylist:export')")
    @Log(title = "清单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopList shopList) {
        List<ShopList> list = shopListService.selectShopListList(shopList);
        ExcelUtil<ShopList> util = new ExcelUtil<ShopList>(ShopList.class);
        util.exportExcel(response, list, "清单管理数据");
    }

    /**
     * 获取清单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:buylist:query')")
    @GetMapping(value = "/{listId}")
    public AjaxResult getInfo(@PathVariable("listId") Long listId) {
        return success(shopListService.selectShopListByListId(listId));
    }

    /**
     * 新增清单管理
     */
    @PreAuthorize("@ss.hasPermi('manage:buylist:add')")
    @Log(title = "清单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopListProductDto shopListProductDto) {
        return toAjax(shopListService.insertShopList(shopListProductDto));
    }

    /**
     * 修改清单管理
     */
    @PreAuthorize("@ss.hasPermi('manage:buylist:edit')")
    @Log(title = "清单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopListProductDto shopListProductDto) {
        return toAjax(shopListService.updateShopList(shopListProductDto));
    }

    /**
     * 删除清单管理
     */
    @PreAuthorize("@ss.hasPermi('manage:buylist:remove')")
    @Log(title = "清单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{listIds}")
    public AjaxResult remove(@PathVariable Long[] listIds) {
        return toAjax(shopListService.deleteShopListByListIds(listIds));
    }
}
